package uk.ac.ebi.pride.tools.pap.soap;

import uk.ac.ebi.pride.tools.pap.generated.PrideAcProviderInterface;
import uk.ac.ebi.pride.tools.pap.generated.Accessions;
import uk.ac.ebi.pride.tools.pap.AccessionProvider;
import uk.ac.ebi.pride.tools.pap.AccessionProviderException;

import javax.jws.WebParam;
import javax.jws.WebService;

import org.apache.log4j.Logger;

/**
 * @author Florian Reisinger
 *         Date: 18-Feb-2009
 * @since $version
 */
@WebService(endpointInterface = "uk.ac.ebi.pride.tools.pap.generated.PrideAcProviderInterface",
        portName = "PrideAcProviderServicePort",
        serviceName = "PrideAcProviderService",
        targetNamespace = "http://ebi.ac.uk/pride/tools/pap",
        wsdlLocation = "WEB-INF/wsdl/accessionProvider.wsdl"
)
public class PapSoapServiceImpl implements PrideAcProviderInterface {

    private static final Logger log = Logger.getLogger(PapSoapServiceImpl.class);

    // worker class generating the accession numbers (retrieval from DB sequence)
    private static final AccessionProvider AC_PROVIDER = new AccessionProvider();

    ///// ///// ///// ///// ///// ///// ///// ///// ///// /////
    // public service methods

    public Accessions getPrideProjectAccessions(@WebParam(name = "getPrideProjectAccessions", targetNamespace = "http://ebi.ac.uk/pride/tools/pap", partName = "input") int input) {
        log.info("SOAP request for " + input + " PRIDE project accessions.");
        Accessions accs = new Accessions();
        try {
            accs.getAc().addAll( AC_PROVIDER.getAccessions(input, AccessionProvider.AcCase.PROJECT) );
        } catch (AccessionProviderException e) {
            log.error("Exception during execution of 'getPrideProjectAccessions(" + input + ")'.", e);
        }
        return accs;
    }

    public Accessions getPrideExpAccessions(@WebParam(name = "getPrideExpAccessions", targetNamespace = "http://ebi.ac.uk/pride/tools/pap", partName = "input") int input) {
        log.info("SOAP request for " + input + " PRIDE experiment accessions.");
        Accessions accs = new Accessions();
        try {
            accs.getAc().addAll( AC_PROVIDER.getAccessions(input, AccessionProvider.AcCase.EXPERIMENT) );
        } catch (AccessionProviderException e) {
            log.error("Exception during execution of 'getPrideExpAccessions(" + input + ")'.", e);
        }
        return accs;
    }

    public Accessions getPrideIdentAccessions(@WebParam(name = "getPrideIdentAccessions", targetNamespace = "http://ebi.ac.uk/pride/tools/pap", partName = "input") int input) {
        log.info("SOAP request for " + input + " PRIDE identification accessions.");
        Accessions accs = new Accessions();
        try {
            accs.getAc().addAll( AC_PROVIDER.getAccessions(input, AccessionProvider.AcCase.IDENTIFICATION) );
        } catch (AccessionProviderException e) {
            log.error("Exception during execution of 'getPrideIdentAccessions(" + input + ")'.", e);
        }
        return accs;
    }

    public Accessions getPridePeptideAccessions(@WebParam(name = "getPridePeptideAccessions", targetNamespace = "http://ebi.ac.uk/pride/tools/pap", partName = "input") int input) {
        log.info("SOAP request for " + input + " PRIDE peptide accessions.");
        Accessions accs = new Accessions();
        try {
            accs.getAc().addAll( AC_PROVIDER.getAccessions(input, AccessionProvider.AcCase.PEPTIDE) );
        } catch (AccessionProviderException e) {
            log.error("Exception during execution of 'getPridePeptideAccessions(" + input + ")'.", e);
        }
        return accs;
    }

    public Accessions getPrideSpectraAccessions(@WebParam(name = "getPrideSpectraAccessions", targetNamespace = "http://ebi.ac.uk/pride/tools/pap", partName = "input") int input) {
        log.info("SOAP request for " + input + " PRIDE spectra accessions.");
        Accessions accs = new Accessions();
        try {
            accs.getAc().addAll( AC_PROVIDER.getAccessions(input, AccessionProvider.AcCase.SPECTRA) );
        } catch (AccessionProviderException e) {
            log.error("Exception during execution of 'getPrideSpectraAccessions(" + input + ")'.", e);
        }
        return accs;
    }

    public Accessions getPrideMzmlAccessions(@WebParam(name = "getPrideMzmlAccessions", targetNamespace = "http://ebi.ac.uk/pride/tools/pap", partName = "input") int input) {
        log.info("SOAP request for " + input + " PRIDE mzML accessions.");
        Accessions accs = new Accessions();
        try {
            accs.getAc().addAll( AC_PROVIDER.getAccessions(input, AccessionProvider.AcCase.MZML) );
        } catch (AccessionProviderException e) {
            log.error("Exception during execution of 'getPrideMzmlAccessions(" + input + ")'.", e);
        }
        return accs;
    }

    public Accessions getPrideAnalysisXmlAccessions(@WebParam(name = "getPrideAnalysisXmlAccessions", targetNamespace = "http://ebi.ac.uk/pride/tools/pap", partName = "input") int input) {
        log.info("SOAP request for " + input + " PRIDE analysisXML accessions.");
        Accessions accs = new Accessions();
        try {
            accs.getAc().addAll( AC_PROVIDER.getAccessions(input, AccessionProvider.AcCase.ANALYSISXML) );
        } catch (AccessionProviderException e) {
            log.error("Exception during execution of 'getPrideAnalysisXmlAccessions(" + input + ")'.", e);
        }
        return accs;
    }

    public Accessions getPrideProteomExchangeAccessions(@WebParam(name = "getPrideProteomExchangeAccessions", targetNamespace = "http://ebi.ac.uk/pride/tools/pap", partName = "input") int input) {
        log.info("SOAP request for " + input + " PRIDE proteomexchange accessions.");
        Accessions accs = new Accessions();
        try {
            accs.getAc().addAll( AC_PROVIDER.getAccessions(input, AccessionProvider.AcCase.PROTEOMEXCHANGE) );
        } catch (AccessionProviderException e) {
            log.error("Exception during execution of 'getPrideProteomExchangeAccessions(" + input + ")'.", e);
        }
        return accs;
    }
}
